package PTA_JAVA.JavaA.Javademo28;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<String,List<Integer>> map = new TreeMap<>();
        String a;
        int line=0;
        List<String> lines = new ArrayList<>();
        while (!"!!!!!".equals(a = sc.nextLine())) {
            String[] s=a.split(" ");
            lines.add(a);
            line++;
            for (int i = 0; i < s.length; i++) {
                if(map.containsKey(s[i])){
                    if(!map.get(s[i]).contains(line)){
                        map.get(s[i]).add(line);
                    }
                }else{
                    List<Integer> list = new ArrayList<>();
                    list.add(line);
                    map.put(s[i],list);
                }
            }
        }
        List<Map.Entry<String, List<Integer>>> list = new ArrayList<>(map.entrySet());
        for (Map.Entry<String, List<Integer>> stringListEntry : list) {
            System.out.println(stringListEntry);
        }
        while(sc.hasNextLine()){
            String[] s = sc.nextLine().split(" ");
            List<Integer> t = new ArrayList();
            for(String i:s){
                if(map.containsKey(i)){
                    if(t.isEmpty()){
                        t = new ArrayList<>(map.get(i));
                    }else{
                        t.containsAll(map.get(i));
                        if(t.isEmpty()){
                            System.out.println("found 0 results");
                            break;
                        }
                    }
                }else{
                    System.out.println("found 0 results");
                    break;
                }
            }
            if(!t.isEmpty()){
                System.out.println(t);
            }
            for(Integer i:t){
                System.out.println("line "+i+":"+lines.get(i-1));
            }
        }
    }
}
